const HASH = "#";
const ZERO = "0";

export const shapes = {};

export const Util = {
  // 随机颜色
  getRandomColor() {
    let randColor = ((Math.random() * 0xffffff) << 0).toString(16);
    while (randColor.length < 6) {
      randColor = ZERO + randColor;
    }
    return HASH + randColor;
  },
  getColorKey() {
    let key = "";
    while (true) {
      key = Util.getRandomColor();
      if (key && !(key in shapes)) {
        break;
      }
    }
    return key;
  },
  rgbToHex(r: number, g: number, b: number) {
    return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  },
  capitalize(str: string) {
    return str.charAt(0).toUpperCase() + str.slice(1);
  },
  isFunction(obj: any) {
    return !!(obj && obj.constructor && obj.call && obj.apply);
  },
  isObject(val: any): val is Object {
    return val instanceof Object;
  },
};
